Skip to content

Conversation

@pR0Ps
Copy link
Contributor

@pR0Ps pR0Ps commented Nov 8, 2017

pytz has a class of timezone called a FixedOffset. This class only
stores an offset, not a zone name.

When calling instance() on a datetime that was using one of these
FixedOffset objects as a timezone, Pendulum would totally ignore the
offset and use the local timezone instead. This would happen even if a
tz argument was directly supplied to the instance() call.

Additionally, the fallback to a fixed offset would always use the
datetime's timezone, even it if was None and a tz argument was
supplied to the instance() call.

This commit makes 2 small changes:

  • The zone property of the "effective timezone" (the datetime's
    tzinfo with a fallback to the passed in tz) is only used if it is
    non-null. This fixes using FixedOffset objects as timezones.
  • The fallback to a fixed offset now uses the offset of the "effective
    timezone" instead of the datetime's offset. This correctly handles
    cases where the timezone on the datetime is None and a fallback is
    provided.

`pytz` has a class of timezone called a `FixedOffset`. This class only
stores an offset, not a zone name.

When calling `instance()` on a datetime that was using one of these
`FixedOffset` objects as a timezone, Pendulum would totally ignore the
offset and use the local timezone instead. This would happen even if a
`tz` argument was directly supplied to the `instance()` call.

Additionally, the fallback to a fixed offset would always use the
datetime's timezone, even it if was `None` and a `tz` argument was
supplied to the `instance()` call.

This commit makes 2 small changes:
- The `zone` property of the "effective timezone" (the datetime's
  `tzinfo` with a fallback to the passed in `tz`) is only used if it is
  non-null. This fixes using `FixedOffset` objects as timezones.
- The fallback to a fixed offset now uses the offset of the "effective
  timezone" instead of the datetime's offset. This correctly handles
  cases where the timezone on the datetime is `None` and a fallback is
  provided.
@sdispater sdispater merged commit a39d8ec into python-pendulum:master Nov 8, 2017
@sdispater
Copy link
Collaborator

Nice catch! Thanks a lot for this PR :-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants